package cn.shop.dys.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Toast;

import java.util.List;

import cn.shop.dys.R;
import cn.shop.dys.activity.ProductActivity;
import cn.shop.dys.bean.ProductListItem;
import cn.shop.dys.widget.NoScrollGridView;
import cn.shop.lib_common.CommonViewHolder;


/**
 * Created by sugar0811 on 2016/4/24.
 */
public class SuperAdapter extends BaseAdapter{
    private Context context;
    private List<ProductListItem> productListItems;
    public SuperAdapter(Context context, List<ProductListItem> productListItems){
        this.context = context;
        this.productListItems = productListItems;

    }



        @Override
        public int getCount() {
            return 1;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            CommonViewHolder holder = CommonViewHolder.getCommonViewHolder(convertView, context, R.layout.item_noscroll_product);
            NoScrollGridView gv_main= holder.getView(R.id.gv_main);
            gv_main.setOnItemClickListener(itemClickListener);
            gv_main.setAdapter(new ProductAdapter(context,productListItems));
            return holder.convertView;
        }
    //  点击产品条目的监听，跳转到产品详情 --  给予条目的id
    AdapterView.OnItemClickListener itemClickListener = new AdapterView.OnItemClickListener() {


        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(context, " " + productListItems.get(position).getId(), Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(context, ProductActivity.class);
            intent.putExtra("pId",productListItems.get(position).getId());
            context.startActivity(intent);
        }
    };

}
